home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / TED.ASM < prev    next >
Assembly Source File  |  1995-01-15  |  16KB  |  647 lines

  1. ; 386POWER example program #1.
  2.  
  3.         .386p
  4. code32 segment para public use32
  5.        assume cs:code32,ds:code32
  6.  
  7. include 386power.inc
  8. include 386video.inc
  9. include 386keyb.inc
  10. include 386timer.inc
  11. include 386mouse.inc
  12. include 386file.inc
  13. include 386arg.inc
  14. include pix.inc
  15. include pcx.inc
  16. include picture.inc
  17. include chario.inc
  18. include pattern.inc
  19. include chtil.inc
  20. include 386menu.inc
  21.  
  22. public  _Main
  23.         align byte
  24. Picture dd 0        
  25. Sprite  dd 0
  26. Pattern dd 0
  27. MouPat  dd 0
  28. MouN    dd 0
  29. PatBase dd 0
  30.  
  31. Pcxname db  'TED.PCX',0
  32. Fntname db  'CHARSET.CBF',0
  33.  
  34. Tilname  dd offset tilfname
  35. tilfname db  'TILES.TBF',0
  36.  
  37. NumTiles dd 0  ; number of tiles loaded
  38.  
  39. flippy dd 0
  40. tiky   dd 0
  41.  
  42. ; map description structure
  43. MAPPA dd (XTILES*YTILES*2) dup(0)
  44.  
  45. ShowBar:
  46.         ; display "halved" patterns
  47.         pushad
  48.         mov ecx,NumTiles
  49.         sub ecx,MouN
  50.         cmp ecx,10
  51.         jb fullh
  52.         mov ecx,10
  53. fullh:
  54.         mov edi,_ScrBase
  55.         mov esi,MouPat 
  56.         mov eax,156+XBORDER
  57.         mov edx,4+RYHEIGHT+YBORDER
  58. hblit:        
  59.         call _PutHPat
  60.         add eax,16
  61.         add esi,TILESIZE
  62.         dec ecx
  63.         jne hblit
  64.         xor eax,eax
  65.         mov edx,RYHEIGHT
  66.         mov ecx,80
  67.         mov ebx,SCOREBOARD
  68.         call _TouchBlock
  69.         popad
  70.         ret
  71.         
  72. epcx    db 'No TED.PCX file found!',CR,LF,'$'
  73. echar   db 'No GREEN.CBF font file found!',CR,LF,'$'
  74. etile   db 'No TILES.TBF font file found!',CR,LF,'$'
  75. mickey_off db 'Mouse Not Installed!',CR,LF,'$'
  76.  
  77. inputs  db 12 dup(0)
  78.         
  79. titlepcx  db 'Tiled Background Editor (press a key)',0
  80.  
  81. TouchAll db 0
  82. test_header db 'T.E.D. menu test',0
  83. test_bar    db 'this is a bar',0
  84. test_int    db 'this is an int entry',0
  85. test_uint   db 'this is an unsigned entry',0
  86. test_key    db 'this is a key entry',0
  87. test_end dd t0,t1,t2
  88. t0       db 'Press ESC to exit this menu',0
  89. t1       db 'use <- -> to inc/dec values',0
  90. t2       db 'or ENTER to select values',0
  91.  
  92. exit_mn db 'press here to edit map',0
  93. exit_sm db 'press here to exit submenu',0
  94. skuzz  dd  20
  95. skint  dd  0
  96. skuint dd 12
  97. flagg  dd 0
  98. picka   dd 0
  99. picktop= 5
  100. picklist dd p0,p1,p2,p3,p4
  101. test_pick db 'pick-list entry',0
  102. test_flag db 'toggle this entry',0
  103. test_string db 'string entry',0
  104. test_submenu db 'enabled submenu entry',0
  105. test_dsub    db 'disabled submenu entry',0
  106. stringg db 11 dup(0)
  107. kkeyy db 0
  108. p0 db ' ULTRALASER  ',0
  109. p1 db ' MACHINE GUN ',0
  110. p2 db 'PLASMA CANNON',0
  111. p3 db ' EMP CANNON  ',0
  112. p4 db 'SWARM MISSILE',0
  113.  
  114. dumb_fn: clc ; make sure nothing will produce a full refresh
  115.          ret
  116.          align byte
  117.  
  118. menutest db M_HEADER,0,38,0
  119.          dd test_header,0,0
  120.          db M_EXIT,0,0,0
  121.          dd exit_mn
  122.          db M_PICK,0,20,13
  123.          dd test_pick,picka,dumb_fn,picklist,picktop
  124.          db M_TOGGLE,2,0,0
  125.          dd test_flag,flagg,dumb_fn
  126.          db M_STRING,0,20,10
  127.          dd test_string,stringg,dumb_fn
  128.          db M_KEY,0,20,0
  129.          dd test_key,kkeyy,dumb_fn
  130.          db M_MENU,0,0,0
  131.          dd test_submenu,submenutest
  132.          db M_MENU,0,0,1
  133.          dd test_dsub,submenutest
  134.          db M_END,1,3,0
  135.          dd test_end
  136.  
  137. submenutest db M_HEADER,0,38,0
  138.             dd test_header,0,0
  139.             db M_EXIT,0,0,0
  140.             dd exit_sm
  141.             db M_BAR,0,18,10
  142.             dd test_bar,skuzz,dumb_fn,0,200,5
  143.             db M_INT,0,27,10
  144.             dd test_int,skint,dumb_fn,-10000,10000,5
  145.             db M_UNSIGNED,0,27,10
  146.             dd test_uint,skuint,dumb_fn,0,10000,5
  147.             db M_TOGGLE,2,0,0
  148.             dd xvde,_XVDExternal,dumb_fn
  149.             db M_TOGGLE,2,0,0
  150.             dd xvdgd,_XVDGoodDriver,dumb_fn
  151.             db M_TOGGLE,2,0,0
  152.             dd xvdbg,_XVDBGood,dumb_fn
  153.             db M_TOGGLE,2,0,0
  154.             dd xvdcg,_XVDCGood,dumb_fn
  155.             db M_END,1,3,0
  156.             dd test_end
  157.  
  158. xvde  db 'external driver',0
  159. xvdgd db 'is an xvd driver',0
  160. xvdbg db 'bios ok',0
  161. xvdcg db 'chipset ok',0
  162.  
  163. _Main:  sti ; enable interrupts and get running
  164.         ; first of all initialize display driver
  165.         mov _DispX,320
  166.         mov _DispY,200
  167.         mov _ScrX,(RXWIDTH+XBORDER)
  168.         mov _ScrY,(VYHEIGHT+(YBORDER*2)+SCOREBOARD+1)
  169.         call _SetXVDMode
  170.         ; position the "view" window into the display buffer
  171.         mov eax,XBORDER
  172.         mov edx,YBORDER
  173.         call _DisplayStart
  174.         
  175.         ; then install the "raw keyboard" driver
  176.         call _KeybInst
  177.         ; initialize COMMAND LINE OPTIONS SCANNER
  178.         call _ArgInit
  179.         
  180.         ; load title screen 
  181.         ; n.b. in ther upper left there is the "pointer" bitmap
  182.         ;      the program will use to show the mouse position
  183.         mov esi,offset Pcxname 
  184.         call _PcxLoad          
  185.         mov _386Return, offset epcx
  186.         cmp _PcxDecoded,0
  187.         je Bye
  188.         call _PageFlip0 ; show image
  189.         
  190.         ; load character font file
  191.         mov _386Return, offset echar
  192.         mov esi,offset Fntname    ; load font into low memory
  193.         call _LoadCharSet         ;
  194.         jc Bye
  195.         
  196.         ; get the mouse cursor image from TED.PCX
  197.         mov esi,_ScrBase
  198.         mov eax,XBORDER
  199.         mov edx,YBORDER
  200.         mov ecx,4  ; 16 pixels = 4 nudget
  201.         mov ebx,13 ; pixels
  202.         mov edi,_LoMemBase
  203.         mov Picture,edi
  204.         call _GetPic
  205.         ; compile it to TRLE bitmap format
  206.         mov  Sprite,edi
  207.         mov  esi,Picture
  208.         call _Pic2Spt
  209.         mov _LoMemBase,edi ; set new _LoMemBase
  210.         
  211.         mov edi,_LoMemBase
  212.         mov _386Return,offset etile
  213.         
  214.         mov PatBase,edi         ; initialize tile control vars
  215.         mov MouPat,edi          ; 
  216.         mov MouN,0              ;
  217.         
  218.         call _ArgFile           ; check if there is a filename into the command
  219.         cmp byte ptr [esi],0    ; line
  220.         je no_tile_override
  221.         mov Tilname,esi         ; default tile file
  222. no_tile_override:        
  223.         mov esi,Tilname         ; Load tile file
  224.         call _LoFLoad           ;
  225.         jc Bye
  226.         mov edi,_LoMemBase      ;
  227.         add edi,eax             ;
  228.         mov _LoMemBase,eax      ;
  229.         
  230.         mov edx,0          ;  How many tiles loaded ?
  231.         mov ebx,TILESIZE   ;
  232.         div ebx            ;
  233.         mov NumTiles,eax   ;
  234.         
  235.         ; initialize TILE MAP
  236.         mov edi,offset MAPPA
  237.         mov ecx,XTILES*YTILES
  238.         mov eax,PatBase ; first pattern is always the "zero pattern"
  239.  
  240.         
  241. minit:
  242.         mov [edi],eax
  243.         add edi,8
  244.         dec ecx
  245.         jne minit
  246.         
  247.         ; show program name
  248.         mov edi,_ScrBase
  249.         mov eax,XBORDER+2
  250.         mov edx,2+RYHEIGHT+YBORDER
  251.         mov ebx, offset titlepcx
  252.         call _PutString
  253.         call _PageFlip0
  254.         push eax
  255.         call _WaitKey ; here we wait a keypress
  256.         pop eax
  257.         ; set up mouse driver
  258.         pushad
  259.         mov esi,MAIN_MOUSE
  260.         mov dword ptr [esi*4+ _MouseX1],0
  261.         mov dword ptr [esi*4+ _MouseY1],0
  262.         mov dword ptr [esi*4+ _MouseX2],304
  263.         mov dword ptr [esi*4+ _MouseY2],169
  264.         call _MouseReset
  265.         mov _386Return,offset mickey_off
  266.         cmp eax,0FFFFh
  267.         je mickey_good
  268.         jmp _Exit
  269. mickey_good:
  270.         popad
  271.  
  272.         mov eax,offset menutest
  273.         call _PopMenu
  274.         ; then turn on the timer handling module
  275.         call _InstallTimer
  276. remap:  
  277.         mov edi,_ScrBase
  278.         mov tiky,0
  279.         mov flippy,0
  280.         ; redraw a complete info bar
  281.         mov eax,XBORDER
  282.         mov edx,RYHEIGHT+YBORDER
  283.         mov ecx,80
  284.         mov ebx,SCOREBOARD
  285.         mov esi,02020202h
  286.         call _Block
  287.         call ShowBar
  288.         mov TouchAll,1
  289.         xor edx,edx
  290.         xor eax,eax
  291.         mov esi,offset MAPPA
  292. tiloop: 
  293.         call _PutMap
  294.         push esi
  295.         mov esi,MAIN_MOUSE
  296.         call _MouseRead
  297.         pop esi
  298.  
  299.         mov ecx,0 ; xincr
  300.         mov ebx,0 ; yincr
  301.         cmp dword ptr _MouseX,2
  302.         jae via
  303.         mov ecx,-8
  304. via:    cmp dword ptr _MouseX,302
  305.         jb col
  306.         mov ecx,8
  307. col:    cmp dword ptr _MouseY,2
  308.         jae vento
  309.         mov ebx,-6
  310. vento:  cmp dword ptr _MouseY,167
  311.         jb film
  312.         mov ebx,6
  313. film:   
  314.         pushad
  315.         mov eax,_MouseX
  316.         mov edx,_MouseY
  317.         mov ecx,4  ; 16 dots wide = 4 dwords
  318.         mov ebx,13 ; 13 dots tall
  319.         call _TouchBlock
  320.         
  321.         add eax,XBORDER
  322.         add edx,YBORDER
  323.         mov esi,Sprite
  324.         mov edi,_ScrBase
  325.         mov ebx,0
  326.         call _PutSpt
  327.         ; now write mouse position
  328.         mov eax,XBORDER+4
  329.         mov edx,9+RYHEIGHT+YBORDER
  330.         mov ebx,_MouseX
  331.         mov ecx,8
  332.         call _PutUnsigned
  333.         add eax,72
  334.         mov ebx,_MouseY
  335.         call _PutUnsigned
  336.         sub eax,XBORDER+72
  337.         sub edx,YBORDER
  338.         mov ecx,34
  339.         mov ebx,8
  340.         call _TouchBlock
  341.         popad
  342.         
  343.         ; now select the page flipping method
  344.         cmp TouchAll,0
  345.         je tflip
  346.         call _PageFlip0
  347.         jmp short flipdone
  348. tflip:
  349.         call _PageFlip1
  350. flipdone:
  351.         mov TouchAll,0                
  352.         
  353.         ; now check if the current position has to be replaced with MouPat
  354.         cmp dword ptr _Buttons,0
  355.         je nomoupress
  356.         pushad
  357.         mov edi,_MouseX
  358.         add eax,edi
  359.         mov esi,_MouseY
  360.         add edx,esi
  361.         mov ecx,eax
  362.         mov ebx,THEIGHT
  363.         mov eax,edx ; y
  364.         shr ecx,5  ; x/32
  365.         mov edx,0
  366.         div ebx
  367.         ;eax = tile row
  368.         mov edx,(XTILES*8)
  369.         mov ebp,MouPat
  370.         mul edx
  371.         mov [eax+ecx*8+ offset MAPPA],ebp
  372.         mov TouchAll,1
  373.         popad
  374.         
  375. nomoupress:
  376.         pushad
  377.         or ecx,ebx
  378.         jz nomoved
  379.         mov TouchAll,1
  380. nomoved:        
  381.         shr eax,5
  382.         mov edx,2+RYHEIGHT+YBORDER
  383.         add eax,XBORDER+156
  384.         mov edi,_ScrBase
  385.         mov cl,0 ; clear pix
  386.         call _Pix
  387.         sub eax,XBORDER
  388.         sub edx,YBORDER
  389.         mov ecx,1
  390.         mov ebx,1
  391.         call _TouchBlock
  392.         popad        
  393.         
  394.         ; change position
  395.         add eax,ecx
  396.         add edx,ebx
  397.         ; check if it's a correct position
  398.         cmp eax,(VXWIDTH-RXWIDTH)
  399.         jl  dnx
  400.         mov eax,(VXWIDTH-RXWIDTH)
  401.         mov ecx,0
  402.         jmp short okx
  403. dnx:    cmp eax,0
  404.         jg  okx
  405.         mov eax,0
  406.         mov ecx,0
  407. okx:    
  408.         cmp edx,(VYHEIGHT-RYHEIGHT)
  409.         jl  dny
  410.         mov edx,(VYHEIGHT-RYHEIGHT)
  411.         mov ebx,0
  412.         jmp short oky
  413. dny:    cmp edx,0
  414.         jg  oky
  415.         mov edx,0
  416.         mov ebx,0
  417. oky:    
  418.         pushad
  419.         shr eax,5
  420.         mov edx,2+RYHEIGHT+YBORDER
  421.         add eax,XBORDER+156
  422.         mov edi,_ScrBase
  423.         mov cl,WHITE
  424.         call _Pix  ;set pix
  425.         sub eax,XBORDER
  426.         sub edx,YBORDER
  427.         mov ecx,1
  428.         mov ebx,1
  429.         call _TouchBlock
  430.         cmp tiky,10
  431.         jb goodtime
  432.         mov tiky,0
  433.         
  434.         call _ReadTimer
  435.         mov ebx,flippy
  436.         mov flippy,eax
  437.         sub eax,ebx
  438.         jg zoks
  439.         mov eax,1
  440. zoks:   mov ebx,eax
  441.         xor edx,edx
  442.         mov eax,11931800
  443.         div ebx
  444.         mov ebx,eax
  445.         mov eax,XBORDER+4
  446.         mov edx,1+RYHEIGHT+YBORDER
  447.         mov ecx,8
  448.         call _PutUnsigned
  449.         push edx
  450.         push eax
  451.         call _ReadTimer
  452.         mov ebx,eax
  453.         pop eax
  454.         pop edx
  455.         add eax,72
  456.         call _PutUnsigned
  457.         sub eax,XBORDER+72
  458.         sub edx,YBORDER
  459.         mov ecx,34
  460.         mov ebx,8
  461.         call _TouchBlock    
  462.         
  463. goodtime:        
  464.         inc tiky
  465.         popad
  466.         
  467.         push eax
  468.         call _ScanKeyb
  469.         mov edi,eax
  470.         pop eax
  471.         
  472.         pushad
  473.         cmp byte ptr [edi+_LEFT],KPRESSED ; has been pressed & released ?
  474.         jne noleft
  475.         mov byte ptr [edi+_LEFT],0 ; reset key
  476.         cmp MouN,0
  477.         je  noleft
  478.         dec MouN
  479.         sub MouPat,TILESIZE
  480.         call ShowBar
  481.         jmp short noright
  482. noleft:
  483.         cmp byte ptr [edi+_RIGHT],KPRESSED ; has been pressed & released ?
  484.         jne noright
  485.         mov byte ptr [edi+_RIGHT],0 ; reset key
  486.         mov eax,NumTiles
  487.         dec eax
  488.         cmp eax,MouN
  489.         jb  noright
  490.         inc MouN
  491.         add MouPat,TILESIZE
  492.         call ShowBar        
  493. noright:popad                
  494.  
  495.         cmp byte ptr [edi+_F2],KPRESSED
  496.         je mapload
  497.         
  498.         cmp byte ptr [edi+_F3],KPRESSED
  499.         je mapsave
  500.         
  501.         cmp byte ptr [edi+_ESC],KPRESSED
  502.         jne tiloop
  503.         call _RestoreTextMode
  504.         mov _386Return,offset ESCed
  505. Bye:        
  506.         jmp _Exit
  507.  
  508. mapname db 31 dup(0)
  509.  
  510. ESCed db 'You pressed ESC to correctly terminate',CR,LF,'$'
  511. load  db 'LOAD FILE?',0
  512. save  db 'SAVE FILE?',0
  513.  
  514. gimmename:
  515.         push ebx
  516.         mov edi,_ScrBase
  517.         mov eax,XBORDER
  518.         mov edx,RYHEIGHT+YBORDER
  519.         mov ecx,80
  520.         mov ebx,SCOREBOARD
  521.         mov esi,02020202h
  522.         call _Block
  523.         mov eax,XBORDER
  524.         mov edx,4+RYHEIGHT+YBORDER
  525.         pop ebx
  526.         call _PutString
  527.         call _PageFlip0
  528.         mov ecx,30
  529.         mov ebx,offset mapname
  530.         mov eax,((10*8)+XBORDER)
  531.         call _GetString
  532.         call _PageFlip0
  533.         ret
  534.         
  535. mapsave:
  536.         mov byte ptr [edi+_F3],0
  537.         pushad
  538. sretry:        
  539.         mov ebx,offset save
  540.         call gimmename
  541.         mov ecx,XTILES*YTILES
  542.         mov ebx,PatBase
  543.         mov esi,offset MAPPA
  544.         mov edi,TILESIZE
  545. indica:        
  546.         mov eax,[esi]
  547.         mov edx,0
  548.         sub eax,ebx
  549.         div edi
  550.         mov [esi],eax
  551.         add esi,8
  552.         dec ecx
  553.         jne indica
  554.         
  555.         mov eax,XTILES*YTILES*8
  556.         mov edi,offset MAPPA
  557.         mov esi, offset mapname
  558.         call _FSave
  559.         
  560.         jc sretry ; if error, retry
  561.         mov ecx,XTILES*YTILES
  562.         mov ebx,PatBase
  563.         mov esi,offset MAPPA
  564.         mov edi,TILESIZE
  565. punta:        
  566.         mov eax,[esi]
  567.         mul edi
  568.         add eax,ebx
  569.         mov [esi],eax
  570.         add esi,8
  571.         dec ecx
  572.         jne punta
  573.         popad
  574.         jmp remap
  575.         
  576. errload db 'WRONG FILE, PRESS & RELEASE SPACE...',0
  577.  
  578. ferror: 
  579.         mov edi,_ScrBase
  580.         mov eax,XBORDER
  581.         mov edx,RYHEIGHT+YBORDER
  582.         mov ecx,80
  583.         mov ebx,SCOREBOARD
  584.         mov esi,02020202h
  585.         call _Block
  586.         mov eax,8+XBORDER
  587.         mov edx,4+YBORDER+RYHEIGHT
  588.         mov ebx, offset errload
  589.         call _PutString
  590.         call _PageFlip0
  591.         push eax
  592.         call _ScanKeyb
  593.         mov edi,eax
  594.         mov byte ptr [edi+ _SPACEBAR],0
  595.         pop eax
  596. waitspace:        
  597.         push eax
  598.         call _WaitKey
  599.         mov edi,eax
  600.         pop eax
  601.         cmp byte ptr [edi+ _SPACEBAR],KPRESSED
  602.         jne waitspace
  603.         mov byte ptr [edi+ _SPACEBAR],0        
  604.         popad
  605.         jmp remap
  606.         
  607. mapload:
  608.         mov byte ptr [edi+_F2],0
  609.         pushad
  610. lretry:        
  611.         mov ebx,offset load
  612.         call gimmename
  613.  
  614.         mov esi, offset mapname
  615.         mov al,0 ; read from file
  616.         call _FOpen
  617.         jc ferror
  618.         call _FSize
  619.         cmp eax,XTILES*YTILES*8
  620.         je okey
  621.         call _FClose
  622.         jmp ferror
  623. okey:        
  624.         mov eax,XTILES*YTILES*8
  625.         mov edi,offset MAPPA
  626.         call _FRead
  627.         call _FClose
  628.         mov ecx,XTILES*YTILES
  629.         mov ebx,PatBase
  630.         mov esi,offset MAPPA
  631.         mov edi,TILESIZE
  632. lpunta:        
  633.         mov eax,[esi]
  634.         mul edi
  635.         add eax,ebx
  636.         mov [esi],eax
  637.         add esi,8
  638.         dec ecx
  639.         jne lpunta
  640. nolretry:        
  641.         popad
  642.         jmp remap
  643.         
  644. code32  ends
  645.         end
  646.  
  647.